package cn.rongdao.jrkabao.ui.remind.adapter;

import android.support.v4.content.ContextCompat;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.TextView;

import com.mifengkong.frtools.ui.adapter.recyclerview.FRBaseRecyclerViewHolder;
import com.mifengkong.frtools.util.FRCollection;
import com.mifengkong.frtools.util.FRString;

import cn.rongdao.jrkabao.R;
import cn.rongdao.jrkabao.bean.remind.RemindMailListBean;

/**
 * Created by jack on 2017/11/24
 */

public class RemindMailListViewHolder extends FRBaseRecyclerViewHolder<RemindMailListBean> {

    private TextView tvContent;

    public RemindMailListViewHolder(View view) {
        super(view);
        tvContent = (TextView) view.findViewById(R.id.irml_tv_name);
    }

    @Override
    protected void onItemDataUpdated(RemindMailListBean remindMailListBean) {
        if (!FRString.isEmpty(remindMailListBean.getEmail())) {
            setEmailContent(remindMailListBean.getEmail(), remindMailListBean.getLast_login());
        } else {
            setShortMessageContent(remindMailListBean.getService_desc(), remindMailListBean.getService_tips());
        }
    }

    private void setEmailContent(String mail, String time) {
        String content = FRCollection.appendAsString(mail, "\n上次导入时间：", time, "");
        setTvContent(content,  FRString.valueOf(mail).length());
    }

    private void setShortMessageContent(String desc, String shortMsg) {
        String content = FRCollection.appendAsString(desc, "\n", shortMsg, "");
        setTvContent(content, FRString.valueOf(desc).length());
    }

    private void setTvContent(String content, int index) {
        SpannableString ss = new SpannableString(content);
        ss.setSpan(new AbsoluteSizeSpan(12, true), index, content.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        ss.setSpan(new ForegroundColorSpan(ContextCompat.getColor(getContext(), R.color.c999999)), index, content.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        tvContent.setText(ss);
    }
}
